/**
* Copyright @ 2023 iAuto (Shanghai) Co., Ltd.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are NOT permitted except as agreed by
* iAuto (Shanghai) Co., Ltd.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/


import React from 'react';
import emptyImg from '@/assets/empty.png';
const emptyText = (status: number | string, emptyName = '能力', bColor = true) => {
    return (
        <div className="flex-column-center-mid" style={{
            width: '100%',
            justifyContent: 'center',
            minHeight: '550px',
            display: 'flex',
            alignItems: 'center',
            fontSize: '16px',
            color: '#9fa0a2',
            textAlign: 'center',
            backgroundColor: bColor ? '#fff' : 'transparent'
        }}>
            <div className="noneTableData">
                <img style={{ width: 120, height: 120, marginBottom: 30 }}
                    src={emptyImg} alt="暂无数据" />
                {status == -1 && <p>暂无状态记录</p>}
                {status == 0 && <p>暂无未发布{emptyName}</p>}
                {status == 1 && <p>暂无已发布{emptyName}</p>}
                {([-1, 0, 1].findIndex(item => item == status) < 0) && <p>暂无{emptyName}数据</p>}
            </div>
        </div>
    )
}

const showTotal = (total: number) => `总共 ${total} 个项目`;

const rowHeaderIcon = {
    '1': {
        text: '',
        style: {
            color: '#000'
        }
    },
    '2': {
        text: '变',
        style: {
            color: '#ff7918'
        }
    },
    '3': {
        text: '删',
        style: {
            color: '#9fa0a2'
        }
    },
    '4': {
        text: '新',
        style: {
            color: '#00a870'
        }
    },
}

const renderModalTitle = (actionType: string) => {
    const titleStr = new Map([
        ['publish', '发布'],
        ['export', '导出'],
        ['default', ''],
    ]);
    return titleStr.get(actionType) || titleStr.get('default');
};

const renderIcon = (type: string) => {
    const titleStr = new Map([
        ['isNew', {
            text: '新',
            style: {
                color: '#00a870'
            }
        }],
        ['isChange', {
            text: '变',
            style: {
                color: '#ff7918'
            }
        }],
        ['isDelete', {
            text: '删',
            style: {
                color: '#9fa0a2'
            }
        }],
        ['default', {
            text: '',
            style: {
                color: '#000'
            }
        }],
    ]);
    return titleStr.get(type) || titleStr.get('default');
};

const downloadFile = (URL: string, file_path = '导出能力文件') => {
    const a = document.createElement('a');
    a.download = file_path;
    a.href = URL;
    a.target = '_blank';
    a.click();
    a.remove();
};

const renderRowClassName = (record: any) => {
    if (record.isNew) {
        return 'row-header-isnew'
    } else if (record.isChange) {
        return 'row-header-ischange'
    } else if (record.isDelete) {
        return 'row-header-isdelete'
    } else if (record.backDetail) {
        return 'row-header-backdetail'
    } else {
        return 'row-header-default'
    }
}

const whiteList = ['40079527', '40070305', '40070415', '40060305', '40070901', '40070902', '40060007', '40070500', '40060500', '40060409', '40070409', '40060415', '9049'];

export { emptyText, showTotal, rowHeaderIcon, renderModalTitle, downloadFile, renderIcon, renderRowClassName, whiteList }